package org.jdsm.flow.gxt.users.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiFactory;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;
import com.sencha.gxt.widget.core.client.ContentPanel;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.info.Info;
import com.sencha.gxt.widget.core.client.toolbar.PagingToolBar;
import org.jdsm.flow.gxt.users.client.widgets.group.GroupsGrid;
import org.jdsm.flow.gxt.users.client.widgets.role.RolesGrid;
import org.jdsm.flow.gxt.users.client.widgets.user.UsersGrid;

/**
 * Created by IntelliJ IDEA.
 * User: mikom
 * Date: 7/5/12
 * Time: 12:24 PM
 */
public class MainLayout implements IsWidget{

    interface MainLayoutUiBinder extends UiBinder<Widget, MainLayout> {
    }

    private static MainLayoutUiBinder ourUiBinder = GWT.create(MainLayoutUiBinder.class);

    @Override
    public Widget asWidget() {
        Widget widget = ourUiBinder.createAndBindUi(this);
        userGrid.getLoader().setLimit(10);
        userToolBar.bind(userGrid.getLoader());

        roleGrid.getLoader().setLimit(10);
        roleToolBar.bind(roleGrid.getLoader());

        groupGrid.getLoader().setLimit(10);
        groupToolBar.bind(groupGrid.getLoader());


        return widget;
    }

    @UiField
    protected UsersGrid userGrid;
    @UiField
    protected PagingToolBar userToolBar;
    @UiField
    protected RolesGrid roleGrid;
    @UiField
    protected PagingToolBar roleToolBar;
    @UiField
    protected GroupsGrid groupGrid;
    @UiField
    protected PagingToolBar groupToolBar;

    @UiFactory
    public ContentPanel createContentPanel(ContentPanel.ContentPanelAppearance appearance){
        return new ContentPanel(appearance);
    }

    @UiHandler("addRole")
    public void onButtonClick(SelectEvent event){
        Info.display("Event name", "clicked");
    }

    @UiHandler("removeRole")
    public void onRemoveRole(SelectEvent event){
        Info.display("Event name", "clicked");
    }

}